%%-----------------------------------------------------------------------%%
%%--- Techniques of Integration -----------------------------------------%%

\chapter{Techniques of Integration}


%%-----------------------------------------------------------------------%%
%%--- Trigonometric substitutions ---------------------------------------%%

\section{Trigonometric substitutions}
\index{trigonometric substitution}

The first homework problem is to compute
%
\begin{equation}
\label{eqn:techniques:inverse_substitution_homework}
\int_{\sqrt{2}}^2 \frac{1}{x^3 \sqrt{x^2 - 1}} \, dx.
\end{equation}
%
Your first idea might be to do some sort of substitution, e.g.
$u = x^2 - 1$, but then $du = 2x \, dx$ is nowhere to be seen and this
simply does not work. Likewise, integration by parts gets us nowhere.
However, a technique called \emph{inverse trigonometric substitution}
and a trigonometric identity easily dispenses with the above integral
and several similar ones. Here is the crucial table:
%
\begin{table}[!htbp]
\centering
\begin{tabular}{|l|l|l|} \hline
Expression & Inverse substitution & Relevant trig. identity \\\hline\hline
$\sqrt{a^2 - x^2}$
& $x = a\sin(\theta),\; -\frac{\pi}{2} \leq \theta \leq \frac{\pi}{2}$
& $1 - \sin^2(\theta) = \cos^2(\theta)$ \\[4pt]
$\sqrt{a^2 + x^2}$
& $x = a\tan(\theta),\; -\frac{\pi}{2} < \theta < \frac{\pi}{2}$
& $1 + \tan^2(\theta) = \sec^2(\theta)$ \\[4pt]
$\sqrt{x^2 - a^2}$
& $x = a\sec(\theta),\; 0 \leq \theta < \frac{\pi}{2}$ or
$\pi \leq \theta < \frac{3\pi}{2}$
& $\sec^2(\theta) - 1 = \tan^2(\theta)$ \\\hline
\end{tabular}
\caption{Inverse trigonometric substitutions.}
\label{tab:techniques:inverse_trigonometric_substitutions}
\end{table}

Inverse substitution works as follows. If we write $x = g(t)$, then
\[
\int f(x) \, dx
=
\int f(g(t)) g'(t) \, dt.
\]
This is \emph{not} the same as substitution. You can just apply
inverse substitution to any integral directly---usually you get
something even worse, but for the integrals in this section using
a substitution can vastly improve the situation.

If $g$ is a one-to-one function, then you can even use inverse
substitution for a definite integral. The limits of integration are
obtained as follows:
%
\begin{equation}
\label{eqn:techniques:inverse_substitution}
\int_a^b f(x) \, dx
=
\int_{g^{-1}(a)}^{g^{-1}(b)} f(g(t)) g'(t) \, dt.
\end{equation}
%
To help you understand this, note that as $t$ varies from
$g^{-1}(a)$ to $g^{-1}(b)$, the function $g(t)$ varies from
$a = g(g^{-1}(a))$ to $b = g(g^{-1}(b))$, so $f$ is being integrated
over exactly the same values. Note also
that~(\ref{eqn:techniques:inverse_substitution}) once again
illustrates Leibniz's brilliance in designing the notation for
calculus.

Let's give it a shot
with~(\ref{eqn:techniques:inverse_substitution_homework}). From
Table~\ref{tab:techniques:inverse_trigonometric_substitutions}, we use
the inverse substitution
\[
x = \sec(\theta)
\]
to obtain
%
\begin{align*}
\int_{\sqrt{2}}^2 \frac{1}{x^3 \sqrt{x^2 - 1}} \, dx
&=
\int_{\frac{\pi}{4}}^{\frac{\pi}{3}}
\frac{1}{\sec(\theta)} {\sqrt{\sec^2(\theta) - 1}}
\sec(\theta)\tan(\theta) \, d\theta \\
&=
\int_{\frac{\pi}{4}}^{\frac{\pi}{3}}
\frac{1}{\sec(\theta)} {\tan(\theta)} \sec(\theta)\tan(\theta) \, d\theta \\
&=
\int_{\frac{\pi}{4}}^{\frac{\pi}{3}} \cos^(\theta) \, d\theta \\
&=
\frac{1}{2} \int_{\frac{\pi}{4}}^{\frac{\pi}{3}}
1 + \cos(2\theta) \, d\theta \\
&=
\frac{1}{2} \left[
\theta + \frac{1}{2} \sin(2\theta) \right]_{\frac{\pi}{4}}^{\frac{\pi}{3}} \\
&=
\frac{\pi}{24} + \frac{\sqrt{3}}{8} - \frac{1}{4}.
\end{align*}
%
This is really an amazing technique. Let's use it again to find the
area of an ellipse.

\begin{example}
Consider an ellipse with radii $a$ and $b$, so it goes through
$(0,\pm b)$ and $(\pm a, 0)$. Find the area of the
ellipse.\index{ellipse!area}
\end{example}

\begin{proof}[Solution]
An equation for the part of an ellipse in the first quadrant is
\[
y
=
b \sqrt{1 - \frac{x^2}{a^2}}
=
\frac{b}{a} \sqrt{a^2 - x^2}.
\]
Thus the area of the entire ellipse is
\[
A
=
4 \int_0^a \frac{b}{a} \sqrt{a^2 - x^2} \, dx.
\]
The $4$ is required because the integral computes one-quarter of the
area of the whole ellipse. So we need to compute
\[
\int_0^a \sqrt{a^2 - x^2} \, dx.
\]
Obvious substitution with $u = a^2 - x^2$? Nope. Integration by parts? Nope.

Let's try inverse substitution. The
Table~\ref{tab:techniques:inverse_trigonometric_substitutions}
suggests using $x = a\sin(\theta)$, so $dx = a\cos(\theta) \, d\theta$.
We get
%
\begin{align*}
\int_0^{\frac{\pi}{2}} \sqrt{a^2 - a^2\sin^2(\theta)} \, d\theta
&=
a^2 \int_0^{\frac{\pi}{2}} \cos^2(\theta) \, d\theta \\
&=
\frac{a^2}{2} \int_0^{\frac{\pi}{2}} 1 + \cos(2\theta) \, d\theta \\
&=
\frac{a^2}{2} \left[
\theta + \frac{1}{2} \sin(2\theta) \right]_0^{\frac{\pi}{2}} \\
&=
\frac{a^2}{2} \cdot \frac{\pi}{2} \\
&=
\frac{\pi a^2}{4}.
\end{align*}
%
Thus the area is
\[
4 \frac{b}{a} \frac{\pi a^2}{4} = \pi a b.
\]
As a consistency check, if the ellipse is a circle, i.e. $a = b = r$,
this is $\pi r^2$, which is a well-known formula for the area of a
circle.
%But, how can trigonometric functions be simpler than algebraic
%functions?  It looks like I'm taking something simple and making
%it more complicated (that's what your math professor always
%does, isn't it?).  But in fact, it turns out that the trigonometric
%integral above was much simpler to evaluate.
\end{proof}

Trigonometric substitution is useful for functions that involve
$\sqrt{a^2 - x^2}$, $\sqrt{x^2 + a^2}$, and $\sqrt{x^2 - a}$,
but \emph{not all at once}. See
Table~\ref{tab:techniques:inverse_trigonometric_substitutions} for how
to do each. Another important technique is
\emph{completing the square}.\index{completing the square}

\begin{example}
Compute $\int \sqrt{5 + 4x - x^2} \, dx$.
\end{example}

\begin{proof}[Solution]
We first \emph{complete the square}:
\[
5 + 4x - x^2
=
5 - (x - 2)^2 + 4
=
9 - (x - 2)^2.
\]
Thus
\[
\int \sqrt{5 + 4x - x^2} \, dx
=
\int \sqrt{9 - (x - 2)^2} \, dx.
\]
%[[Draw a right triangle with sides
%$x-2$ and $\sqrt{9-(x-2)^2}$ and hypotenuse
%$3$, with angle $\theta$.
We do a usual substitution to get rid of the term $x - 2$. Let
$u = x - 2$ so $du = dx$. Then
\[
\int \sqrt{9 - (x - 2)^2} \, dx
=
\int \sqrt{9 - y^2} \, dy.
\]
Now we have an integral that we can do. It is almost identical to the
previous example, but with $a = 9$ (and this is an indefinite integral).
Let $y = 3\sin(\theta)$ so $dy = 3\cos(\theta) \, d\theta$. Then
%
\begin{align*}
\int \sqrt{9 - (x - 2)^2} \, dx
&=
\int \sqrt{9 - y^2} \, dy \\
&=
\int \sqrt{3^2 - 3^2\sin^2(\theta)} 3\cos(\theta) \, d\theta \\
&=
9 \int \cos^2(\theta) \, d\theta \\
&=
\frac{9}{2} \int 1 + \cos(2\theta) \, d\theta \\
&=
\frac{9}{2} \left( \theta + \frac{1}{2} \sin(2\theta) \right) + C.
\end{align*}
%
Of course, we \emph{must transform} back into a function in $x$ and
that is a little tricky. Use
\[
x - 2
=
y
=
3\sin(\theta)
\]
so that
\[
\theta
=
\sin^{-1} \left( \frac{x - 2}{3} \right).
\]
Then
%
\begin{align*}
\int \sqrt{9 - (x - 2)^2} \, dx
&=
\frac{9}{2} \left( \theta + \frac{1}{2} \sin(2\theta) \right) + C \\
&=
\frac{9}{2} \left[
  \sin^{-1} \left( \frac{x-2}{3} \right) +
  \sin(\theta)\cos(\theta) \right] + C \\
&=
\frac{9}{2} \left[
  \sin^{-1} \left( \frac{x - 2}{3} \right) +
  \left( \frac{x - 2}{3} \right) \cdot
  \left( \frac{\sqrt{9 - (x - 2)^2}}{3} \right) \right] + C.
 \end{align*}
Here we use $\sin(2\theta) = 2\sin(\theta)\cos(\theta)$. Also, to
compute
$\cos \left( \sin^{-1} \left( \frac{x - 2}{3} \right) \right)$,
we draw a right triangle with side lengths $x - 2$ and
$\sqrt{9 - (x - 2)^2}$, and hypotenuse $3$.
\end{proof}

\begin{example}
Compute
\[
\int \frac{1}{\sqrt{t^2 - 6t + 13}} \, dt.
\]
\end{example}

\begin{proof}[Solution]
To compute this, we complete the square, etc.
%
\begin{align*}
\int \frac{1}{\sqrt{t^2 - 6t + 13}} \, dt
&=
\int \frac{1}{\sqrt{(t-3)^2 + 4}} \, dt
\end{align*}
%
You may want to visualize a triangle with sides $2$ and $t-3$ and
hypotenuse $\sqrt{(t-3)^2 + 4}$. Then
%
\begin{align*}
t - 3
&=
2\tan(\theta) \\
\sqrt{(t-3)^2 + 4}
&=
2\sec(\theta) = \frac{2}{\cos(\theta)} \\
dt
&=
2\sec^2(\theta) \, d\theta.
\end{align*}
%
Back to the integral, we have
%
\begin{align*}
\int \frac{1}{\sqrt{(t-3)^2 + 4}} \, dt
&=
\int \frac{2\sec^2(\theta)}{2\sec(\theta)} \, d\theta \\
&=
\int \sec(\theta) \, d\theta \\
&=
\ln | \sec(\theta) + \tan(\theta)| + C \\
&=
\ln \left| \frac{\sqrt{(t-3)^2 + 4}}{2} + \frac{t-3}{2} \right| + C.
\end{align*}
%
as required.
\end{proof}

%% for exercises, see 8.5 trig subs


%%-----------------------------------------------------------------------%%
%%--- Integration by parts ----------------------------------------------%%

\section{Integration by parts}
\index{integration by parts}

The product rule is that
\[
\frac{d}{dx} \big( f(x) g(x) \big)
=
f(x) g'(x) + f'(x) g(x).
\]
Integrating both sides leads to a new fundamental technique for
integration:
%
\begin{equation}
\label{eqn:techniqes:integration_by_parts}
f(x)g(x)
=
\int f(x) g'(x) \, dx + \int g(x) f'(x) \, dx.
\end{equation}
%
Now rewrite~(\ref{eqn:techniqes:integration_by_parts}) as
\[
\int f(x) g'(x) \, dx
=
f(x)g(x) - \int g(x) f'(x) \, dx
\]
and use the shorthand notation
%
\begin{align*}
u &= f(x) &du &= f'(x) \, dx \\
v &= g(x) &dv &= g'(x) \, dx.
\end{align*}
%
Then we have
\[
\int u \, dv = uv - \int v \, du.
\]
Why is this important? Integration by parts is a fundamental technique
of integration. It is also a key step in the proof of many theorems
in calculus.

\begin{example}
Use integration by parts to compute $\int x \cos(x) \, dx$.
\end{example}

\begin{proof}[Solution]
Use the substitutions
%
\begin{align*}
u &= x & v &= \sin(x) \\
du &= dx & dv &= \cos(x) \, dx
\end{align*}
%
to get
\[
\int x \cos(x) \, dx
=
x\sin(x) - \int \sin(x) \, dx
=
x\sin(x) + \cos(x) + C.
\]
``Did this do anything for us?''  Indeed, it did.

Wait a minute---how did we know to pick $u = x$ and $v = \sin(x)$? We
could have picked them the other way around and still written down
true statements. Let's try that:
%
\begin{align*}
u &= \cos(x)  & v &= \frac{1}{2} x^2 \\
du &= -\sin(x) \, dx & dv &= x \, dx
\end{align*}
%
Then
\[
\int x \cos(x) \, dx
=
\frac{1}{2} x \cos(x) + \int \frac{1}{2} x^2 \sin(x) \, dx.
\]
Did this help? Not at all. Integrating $x^2 \sin(x)$ is harder than
integrating $x \cos(x)$. This formula is completely correct, but is
hampered by being useless in this case. So how \emph{do} you pick
them?
%
\begin{quote}
Choose the $u$ so that when you differentiate it you get something
\emph{simpler}. When you pick $dv$, try to choose something whose
antiderivative is \emph{simpler}.
\end{quote}
%
Sometimes you have to try more than once. But with a good eraser,
nobody will know that it took you two tries. If integration by parts
once is good, then sometimes twice is even better? Yes, in some
examples~(see Example~\ref{ex:parts2}). But in the above example, you
just undo what you did and basically end up where you started, or you
get something even worse.
\end{proof}

\begin{example}
Compute $\ds \int_0^{\frac{1}{2}} \sin^{-1}(x) \, dx$ using
integration by parts.
\end{example}

\begin{proof}[Solution]
Two points to keep in mind:
%
\begin{enumerate}
\item It is a definite integral.

\item There is only one function. Would you think to do integration by
  parts? But it is a product. It just does not look like that at first
  glance.
\end{enumerate}
%
Your choice is made for you, since we would be
\emph{back where we started} if we put $dv = \sin^{-1}(x) \, dx$:
%
\begin{align*}
u &= \sin^{-1}(x) &v &= x \\
du &= \frac{1}{\sqrt{1 - x^2}}  &dv &= dx.
\end{align*}
%
Then we get
\[
\int_0^{\frac{1}{2}} \sin^{-1}(x) \, dx
=
\Bigl[ x\sin^{-1}(x) \Bigr]_0^{\frac{1}{2}} -
\int_0^{\frac{1}{2}} \frac{x}{\sqrt{1 - x^2}} \, dx.
\]
Now use substitution with $w = 1 - x^2$ and $dw = -2x \, dx$, hence
$xdx = -\frac{1}{2} \, dw$:
\[
\int_0^{\frac{1}{2}} \frac{x}{\sqrt{1 - x^2}} \, dx
=
-\frac{1}{2} \int w^{-\frac{1}{2}} \, dw
=
-w^{\frac{1}{2}} + C
=
-\sqrt{1 - x^2} + C.
\]
Hence
\[
\int_0^{\frac{1}{2}} \sin^{-1}(x) \, dx
=
\Bigl[ x\sin^{-1}(x) \Bigr]_0^{\frac{1}{2}} +
\left[ \sqrt{1 - x^2} \right]^{\frac{1}{2}}_0
=
\frac{\pi}{12} + \frac{\sqrt{3}}{2} - 1.
\]
But shouldn't we change the limits because we did a substitution? No,
since we computed the indefinite integral and put it back. This time,
we used the other option.

Is there another way to do this? I'm not sure. But for any integral,
there might be several different techniques. If you can think of any
other way to guess an antiderivative, do it. You can always
differentiate as a check. Note: Integration by parts is tailored
toward doing indefinite integrals.
\end{proof}

\begin{example}
This example illustrates how to use integration by parts twice. Compute
\[
\int x^2 e^{-2x} \, dx.
\]
\end{example}

\begin{proof}[Solution]
Using the substitutions
%
\begin{align*}
u &= x^2 & v &= -\frac{1}{2} e^{-2x} \\
du &= 2x \, dx  & dv &= e^{-2x} \, dx
\end{align*}
%
we have
%
\begin{equation}
\label{eqn:techniques:integration_parts_twice}
\int x^2 e^{-2x} \, dx
=
-\frac{1}{2} x^2 e^{-2x} + \int x e^{-2x} \, dx.
\end{equation}
%
Did this help? It helped, but it did \emph{not} finish the integral
off.  However, we can deal with the remaining integral, again using
integration by parts. If you do it twice, you
\emph{want to keep going in the same direction}. Do not switch your
choice, or you will undo what you just did. Make the substitutions
%
\begin{align*}
u &= x  & v &= -\frac{1}{2} e^{-2x} \\
du &= dx  & dv &= e^{-2x} \, dx
\end{align*}
%
to get
\[
\int x e^{-2x} \, dx
=
- \frac{1}{2} x e^{-2x} + \frac{1}{2} \int e^{-2x} \, dx
=
- \frac{1}{2} x e^{-2x} - \frac{1}{4} e^{-2x} + C.
\]
%
Now substitute the latter equation
into~(\ref{eqn:techniques:integration_parts_twice}) to get
\[
\int x^2 e^{-2x} \, dx
=
-\frac{1}{2} x^2 e^{-2x} - \frac{1}{2} x e^{-2x} - \frac{1}{4} e^{-2x} + C
\]
which simplifies to $-\frac{1}{4} e^{-2x}(2x^2 + 2x + 1) + C$.
\end{proof}

Do you think you might have to do integration by parts three times?
What if it were $\int x^3 e^{-2x} \, dx$? Then you would have to do it
three times.

\begin{example}
\label{ex:parts2}
Compute $\int e^x \cos(x) \, dx$.
\end{example}

\begin{proof}[Solution]
Which should be $u$ and which should be $v$? Taking the derivatives
of each type of function does not change the type. As a practical
matter, it does not matter. Which would you \emph{prefer} to find the
antiderivative of? (Both choices work, as long as you keep going in
the same direction when you do the second step.) Use the substitutions
%
\begin{align*}
u &= \cos(x)  & v &= e^x \\
du &= -\sin(x) \, dx  & dv &= e^x \, dx
\end{align*}
to get
\[
\int e^x \cos(x) \, dx
=
e^x \cos(x) + \int e^x \sin(x) \, dx.
\]
We have to do it again. This time we choose (going in the
\emph{same direction}):
%
\begin{align*}
u &= \sin(x) & v &= e^x \\
du &= \cos(x) \, dx  & dv &= e^x \, dx.
\end{align*}
Then we get
\[
\int e^x \cos(x) \, dx
=
e^x \cos(x) + e^x \sin(x) - \int e^x \cos(x) \, dx.
\]
Did we get anywhere? Yes and no. First impression: all this work and
we are back where we started from. Clearly we do not want to integrate
by parts yet again. However, notice the \emph{minus} sign in front of
$\int e^x \cos(x) \, dx$. You can add the integral to both sides and
get
\[
2 \int e^x \cos(dx)
=
e^x \cos(x) + e^x \sin(x) + C.
\]
Hence
\[
\int e^x \cos(dx)
=
\frac{1}{2} e^x (\cos(x) + \sin(x)) + C
\]
as required.
\end{proof}


\subsection{More general uses of integration by parts}

The formula for integration by parts is also used to derive many of
the entries in the table of integrals at the end of the book. For some
integrands such as $x^n \ln(x)$, the result is simply a function, an
antiderivative of the integrand. For some integrands such as
$\sin(x)^n$, the result is a reduction formula, a formula which still
contains an integral, but the new integrand is the sine function
raised to a smaller power, $\sin(x)^{n-2}$. By repeatedly applying the
reduction formula, we can evaluate the integral of sine raised to any
positive integer power.

%{\bf General Patterns}

\begin{practice}
Let $n \neq -1$ be an integer. Evaluate
$\int x^n \ln(x) \, dx$ using $u = \ln(x)$ and $dv = x^n \, dx$.
\end{practice}

\begin{practice}
Let $n \neq -1$ be an integer. Apply integration by parts to
$\int x^n e^x \, dx$ using $u = x^n$ and $dv = e^x \, dx$.
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Factoring polynomials ---------------------------------------------%%

\section{Factoring polynomials}
%\forclass{Quizes today!}
\index{polynomial factorization}

How do you compute something like
\[
\int \frac{x^2 + 2}{(x-1) (x+2) (x+3)} \, dx?
\]
So far you have no method for doing this. The trick (which is called
partial fraction decomposition) is to write
%
\begin{equation}
\label{eqn:polyfacinttex}
\int \frac{x^2 + 2}{x^3 + 4x^2 + x - 6} \, dx
=
\int \frac{1}{4(x-1)} - \frac{2}{x+2} + \frac{11}{4(x+3)} \, dx.
\end{equation}
%
The integral on the right is then easy to do (the answer involves $\ln$).

But \emph{how on earth} do you get the rational function on the
left-hand side to be a sum of the nice terms as given on the
right-hand side? Doing this is called
\emph{partial fraction decomposition}
\index{partial fraction decomposition} and it is a fundamental idea in
mathematics. It relies on our ability to factor polynomials and solve
linear equations. As a first hint, notice that
\[
x^3 + 4x^2 + x - 6
=
(x - 1) \cdot (x + 2) \cdot (x + 3)
\]
so the denominators in the decomposition correspond to the factors of
the denominator.

Before describing the secret behind~(\ref{eqn:polyfacinttex}), we will
discuss some background about how polynomials and rational functions
work.

\begin{theorem}
\textbf{Fundamental Theorem of Algebra.}
\index{Fundamental Theorem of Algebra}
If $f(x) = a_n x^n + \cdots + a_1 x + a_0$ is a polynomial, then there
are complex numbers $c, \alpha_1, \dots, \alpha_n$ such that
\[
f(x)
=
c (x - \alpha_1) (x - \alpha_2) \cdots (x - \alpha_n).
\]
\end{theorem}

For example,
\[
3x^2 + 2x - 1
=
3 \cdot \left( x - \frac{1}{3} \right) \cdot (x + 1)
\]
and
\[
(x^2 + 1)
=
(x + i)^2 \cdot (x - i)^2.
\]
If $f(x)$ is a polynomial, the roots $\alpha$ of $f$ correspond to the
factors of $f$. Thus if
\[
f(x)
=
c (x - \alpha_1) (x - \alpha_2) \cdots (x - \alpha_n)
\]
then
$f(\alpha_i) = 0$ for each $i$ (and nowhere else).

\begin{definition}
\textbf{Multiplicity of zero.}
\index{multiplicity of zero}
The \emph{multiplicity of a zero} $\alpha$ of $f(x)$ is the number of
times that $(x - \alpha)$ appears as a factor of $f$.
\end{definition}

For example, if
$f(x) = 7(x - 2)^{99} \cdot (x + 17)^5 \cdot (x - \pi)^2$, then $2$ is
a zero with multiplicity $99$, $\pi$ is a zero with multiplicity $2$,
and $-1$ is a ``zero with multiplicity $0$.''

\begin{definition}
\textbf{Rational function.}
\index{rational function}
A \emph{rational function} is a quotient
\[
f(x)
=
\frac{g(x)}{h(x)}
\]
where $g(x)$ and $h(x)$ are polynomials.
\end{definition}

For example,
%
\begin{equation}
\label{eqn:ratfun1}
f(x)
=
\frac{x^{10}}{(x - i)^2 (x + \pi) (x - 3)^3}
\end{equation}
%
is a rational function.

\begin{definition}
\textbf{Pole.}
\index{pole}
A \emph{pole} of a rational function $f(x)$ is a complex number
$\alpha$ such that $|f(x)|$ is unbounded as $x \to \alpha$.
\end{definition}

For example, for~(\ref{eqn:ratfun1}) the poles are at $i$, $\pi$, and
$3$. They have multiplicity $2$, $1$, and $3$, respectively.


%%-----------------------------------------------------------------------%%
%%--- Partial fractions -------------------------------------------------%%

\section{Partial fractions}
\index{partial fractions}

Rational functions (polynomials divided by polynomials) and their
integrals are important in mathematics and applications. However, if
you look through a table of integral formulas, you will find very few
formulas for their integrals. That is partly because the general
formulas are rather complicated and have many special cases, and
partly it is because they can all be reduced to just a few cases using
the algebraic technique discussed in this section, partial fraction
decomposition. In algebra you learned to add rational functions to get
a single rational function. Partial fraction decomposition is a
technique for reversing that procedure to \emph{decompose} a single
rational function into a sum of simpler rational functions. Then the
integral of the single rational function can be evaluated as the
sum of the integrals of the simpler functions.

\begin{example}
\label{ex:techniques:decomposed_fraction_integration}
Use the algebraic decomposition
\[
\frac{17x - 35}{2x^2 - 5x} = \frac{7}{x} + \frac{3}{2x - 5}
\]
to evaluate $\int \frac{17x - 35}{2x^2 - 5x} \, dx$.
\end{example}

\begin{proof}[Solution]
The decomposition allows us to exchange the original integral
for two much easier ones:
%
\begin{align*}
\int \frac{17x - 35}{2x^2 - 5x} \, dx
&=
\int \frac{7}{x} \, dx + \int \frac{3}{2x - 5} \, dx \\
&=
7\ln|x| + \frac{3}{2} \ln|2x - 5| + C.
\end{align*}
%
When \sage computes this integral, it implicitly assumes that $x > 0$:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: integral((17*x - 35) / (2*x^2 - 5*x), x)
3/2*log(2*x - 5) + 7*log(x)
\end{lstlisting}
\end{center}
%
Note that \sage also leaves off the constant of integration, but this
is more of an abbreviation than a matter of precision.
\end{proof}

\begin{practice}
Use the algebraic decomposition
\[
\frac{7x - 11}{3x^2 - 8x - 3} = \frac{4}{3x+1} + \frac{1}{x-3}
\]
to evaluate $\int \frac{7x - 11}{3x^2 - 8x - 3} \, dx$.
\end{practice}

Example~\ref{ex:techniques:decomposed_fraction_integration}
illustrates how to use a decomposed fraction with integrals, but it
does not show how to achieve the decomposition. The algebraic basis
for the partial fraction decomposition technique is that every
polynomial can be factored into a product of linear factors
$ax + b$ and irreducible quadratic factors $ax^2 + bx + c$ (with
$b^2- 4ac < 0$). These factors may not be easy to find and they will
typically be more complicated than the examples in this section, but
every polynomial has such factors. Before we apply the partial
fraction decomposition technique, the fraction must have
the following form:
%
\begin{itemize}
\item[(a)] (the degree of the numerator) $<$ (degree of the denominator);

\item[(b)] the denominator has been factored into a product of linear
  factors and irreducible quadratic factors.
\end{itemize}
%
If assumption~(a) is not true, we can use polynomial division until we
get a remainder which has a smaller degree than the denominator. If
assumption~(b) is not true, we simply cannot use the partial fraction
decomposition technique.


\subsubsection*{Distinct linear factors}
\index{factors!linear}

If the denominator can be factored into a product of distinct linear
factors, then the original fraction can be written as the sum of
fractions of the form
\[
\frac{\text{number}}{\text{linear factor}}.
\]
Our job is to find the values of the numbers in the numerators and
that typically requires solving a system of equations.

\begin{example}
Find constants $A$ and $B$ such that
\[
\frac{17x - 35}{(2x - 5)x} = \frac{A}{x} + \frac{B}{2x - 5}.
\]
\end{example}

\begin{proof}[Solution]
First, note the roots of the denominator are $\{ 0,\, 5/2 \}$. Cross
multiply to get
\[
17x - 35
=
A(2x - 5) + Bx.
\]
Now eliminate $B$ and solve for $A$ using the first root $x = 0$:
\[
-35
=
17\cdot 0 - 35
=
A(2 \cdot 0 - 5) + B \cdot 0
=
-5A.
\]
This gives $A = 7$. Next, eliminate $A$ and solve for $B$ using the
second root $x = 5/2$:
\[
17 \cdot 5/2 - 35
=
A(2 \cdot 5/2 - 5) + B5/2
=
5B/2.
\]
This gives $B = 3$, so we have
\[
\frac{17x - 35}{2x^2 - 5x}
=
\frac{7}{x} + \frac{3}{2x - 5}.
\]
In \sage this is very easy:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: f = (17*x - 35) / (2*x^2 - 5*x)
sage: f.partial_fraction()
3/(2*x - 5) + 7/x
\end{lstlisting}
\end{center}
\end{proof}

\begin{practice}
Find values of $A$ and $B$ so
\[
\frac{6x - 7}{(x + 3) (x - 2)}
=
\frac{A}{x + 3} + \frac{B}{x - 2}.
\]
\end{practice}

In general, there is one unknown coefficient for each distinct linear
factor of the denominator. However, if the number of distinct linear
factors is large, we would need to solve a large system of equations
for the unknowns.

\begin{practice}
Using partial fractions, solve
\[
\int \frac{2x^2 + 7x + 9}{x(x + 1) (x + 3)}.
\]
\end{practice}

Other possible cases are listed as follows. (Of course, a rational
function can involve more than one case as well.)

\begin{itemize}
\item \emph{Distinct irreducible quadratic factors.}
  \index{factors!quadratic}
  \index{factors!irreducible}
  If the factored denominator includes a distinct irreducible
  quadratic factor, then the partial fraction decomposition sum
  contains a fraction of the form of a linear polynomial with unknown
  coefficients divided by the irreducible quadratic factor:
  \[
  \frac{ax + b}{cx^2 + dx + e}.
  \]

\item \emph{Repeated factors.} \index{factors!repeated}
  If the factored denominator contains a
  linear factor raised to a power (greater than one), then we need to
  start the decomposition with several terms. There should be one term
  with one unknown coefficient for each power of the linear
  factor. For example,
  \[
  \frac{ax + b}{(cx + d)^s}.
  \]
\end{itemize}

Here is the general procedure:

\subsubsection*{Partial fraction decomposition of $N(x)/D(x)$}
\index{partial fraction decomposition}

Let $N(x)$ be a polynomial of lower degree than another polynomial $D(x)$.
%This is a method of rewriting a rational function as a
%sum of simpler rational functions.
%To apply the PFDs to a quotient of
%polynomials $N(x)/D(x)$, the degree of the numerator $N(x)$ must be
%strictly smaller than the degree of the denominator $D(x)$. If
%this is not the case, you must first use long division to
%reduce the degree of the numerator.
%
\begin{enumerate}
\item Factor $D(x)$ into irreducible factors having real
  coefficients. Now $D(x)$ is a product of distinct terms of the form
  $(ax + b)^r$ or $(ax^2 + bx + c)^s$, for some integers $r > 0$ and
  $s > 0$. For each term $(ax + b)^r$, the partial fraction
  decomposition of $N(x) / D(x)$ contains a sum of terms of the form
  \[
  \frac{A_1}{(ax + b)} + \cdots + \frac{A_r}{(ax + b)^r}
  \]
  for some constants $A_i$. For each term $(ax^2 + bx + c)^r$, the
  partial fraction decomposition of $N(x) / D(x)$ contains a sum of
  terms of the form
  \[
  \frac{B_1 x + C_1}{(ax^2 + bx + c)} + \cdots +
  \frac{B_s x + C_s}{(ax^2 + bx + c)^s}
  \]
  for some constants $B_i$ and $C_i$. Then ${N(x) / D(x)}$ is the sum
  of all these simpler rational functions.

\item Now you have an expression for $N(x) / D(x)$ which is a sum of
  simpler rational functions. The next step is to solve for the various
  constants $A_i$, $B_i$, $C_i$ occurring in the numerators. Cross
  multiply both sides by $D(x)$ and expand out the resulting
  polynomial identity for $N(x)$ in terms of the $A_i$, $B_i$, $C_i$.
  Equating coefficients of powers of $x$ on both sides gives rise to a
  linear system of equations for the $A_i$, $B_i$, $C_i$ which you can
  solve.
\end{enumerate}

\begin{practice}
\textbf{Logistic growth.}
\index{logistic growth}
The growth rate of many different populations depends not only on the
number of individuals~(leading to
exponential growth)\index{exponential growth} but also on a
\emph{carrying capacity}\index{carrying capacity} of the
environment. If $x$ is the population at time $t$, and the growth rate
of $x$ is proportional to the product of the population and the
carrying capacity $M$ minus the population, then the growth rate is
described by the differential equation
\[
\frac{dx}{dt}
=
k x (M - x)
\]
where $k$ and $M$ are constants for a given species in a given
environment. Let $k = 1$ and $M = 100$, and assume the initial
population is $x(0) = 5$.
%
\begin{itemize}
\item[(a)] Solve the differential equation
  $\frac{dx}{dt} = k x (M - x)$ for $x$.

\item[(b)] Graph the population $x(t)$ for $0 \leq t \leq 20$.

\item[(c)] When will the population be $20$? $50$? $90$? $100$?

\item[(d)] What is the population after a ``long'' time? (Find the
  limit, as $t$ becomes arbitrarily large, of $x$.)

\item[(e)] Explain the shape of the graph in~(a) in terms of a
  population of bacteria.

\item[(f)] When is the growth rate largest? (Maximize $dx/dt$.)

\item[(g)] What is the population when the growth rate is largest?
\end{itemize}
\end{practice}

\begin{practice}
\textbf{Chemical reaction.}
\index{chemical reaction}
In some chemical reactions, a new material
$X$ is formed from materials $A$ and $B$, and the rate at which $X$
forms is proportional to the product of the amount of $A$ and the
amount of $B$ remaining in the solution. Let $x$ represent the amount
of material $X$ present at time $t$, and assume that the reaction
begins with $a$ grams of $A$, $b$ grams of $B$, and no material $X$
($x(0) = 0$). Then the rate of formation of material $X$ can be
described by the differential equation
\[
\frac{dx}{dt}
=
k (a - x) (b - x).
\]
Solve the differential equation for $x$ if $k = 1$ and the reaction
begins with
%
\begin{itemize}
\item[(i)] $7$ grams of $A$ and $5$ grams of $B$; and

\item[(ii)] $6$ grams of $A$ and $6$ grams of $B$.
\end{itemize}
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Integrating rational functions using partial fractions ------------%%

\section{Integrating rational functions using partial fractions}
%\forclass{
%Today: 7.4: Integration of rational functions and
%Supp. 4: Partial fraction expansion\\
%Next: 7.7: Approximate integration}

Our goal in this section is to compute  integrals of the form
\[
\int \frac{P(x)}{Q(x)} \, dx
\]
by decomposing $f = \frac{P(x)}{Q(x)}$. This is called partial
fraction expansion.

\begin{theorem}
\textbf{Fundamental Theorem of Algebra over the real numbers.}
\index{Fundamental Theorem of Algebra}
A real polynomial of degree $n \geq 1$ can be factored as a constant
times a product of linear factors $x - a$ and irreducible quadratic
factors $x^2 + bx + c$.
\end{theorem}

Note that $x^2 + bx + c = (x - \alpha) (x - \bar{\alpha})$, where
$\alpha = z + iw$ and $\bar{\alpha} = z - iw$ are complex conjugates.


\subsubsection*{Types of rational functions $f(x)=\frac{P(x)}{Q(x)}$}
\index{rational functions}

To do a partial fraction expansion, first make sure
$\deg(P(x)) < \deg(Q(x))$ using long division. Then there are four
possible situation, each of increasing generality (and difficulty):
%
\begin{enumerate}
\item $Q(x)$ is a product of distinct linear factors;

\item $Q(x)$ is a product of linear factors, some of which are repeated;

\item $Q(x)$ is a product of distinct irreducible quadratic factors,
  along with linear factors some of which may be repeated; and

\item $Q(x)$ is has repeated irreducible quadratic factors, along with
  possibly some linear factors which may be repeated.
\end{enumerate}

The general partial fraction expansion theorem is beyond the scope of
this book.  However, you might find the following special case and its
proof interesting.

\begin{theorem}
Suppose $p$, $q_1$, and $q_2$ are polynomials that are relatively
prime (have no factors in common). Then there exists polynomials
$\alpha_1$ and $\alpha_2$ such that\index{relatively prime}
\[
\frac{p}{q_1 q_2}
=
\frac{\alpha_1}{q_1} + \frac{\alpha_2}{q_2}.
\]
\end{theorem}

\begin{proof}
Since $q_1$ and $q_2$ are relatively prime, using the Euclidean
algorithm (long division) we can find polynomials $s_1$ and $s_2$
such that\index{Euclidean algorithm}\index{long division}
\[
1 = s_1 q_1 + s_2 q_2.
\]
Dividing both sides by $q_1 q_2$ and multiplying by $p$ yields
\[
\frac{p}{q_1 q_2}
=
\frac{\alpha_1}{q_1} + \frac{\alpha_2}{q_2}
\]
which completes the proof.
\end{proof}

\begin{example}
Compute
\[
\int \frac{x^3 - 4x - 10}{x^2 - x - 6} \, dx.
\]
\end{example}

\begin{proof}[Solution]
First do long division to obtain the quotient $x + 1$ and remainder
$3x - 4$. This means that
\[
\frac{x^3 - 4x - 10}{x^2 - x - 6}
=
x + 1 + \frac{3x - 4}{x^2 - x - 6}.
\]
Since we have distinct linear factors, we know that we can write
\[
f(x)
=
\frac{3x - 4}{x^2 - x - 6}
=
\frac{A}{x - 3} + \frac{B}{x + 2}
\]
for real numbers $A$ and $B$. A clever way to find $A$ and $B$ is to
substitute appropriate values in, as follows. We have
\[
f(x) (x - 3)
=
\frac{3x - 4}{x + 2}
=
A + B \cdot \frac{x - 3}{x + 2}.
\]
Setting $x = 3$ on both sides, we have (taking a limit):
\[
A
=
f(3)
=
\frac{3 \cdot 3 - 4}{3 + 2}
=
\frac{5}{5}
=
1.
\]
Likewise,
\[
B
=
f(-2)
=
\frac{3 \cdot (-2) - 4}{-2 - 3}
=
2.
\]
Thus
%
\begin{align*}
\int \frac{x^3 - 4x - 10}{x^2 - x - 6} \, dx
&=
\int x + 1 + \frac{1}{x - 3} + \frac{2}{x + 2} \\
&=
\frac{x^2 + 2x}{2} + 2 \log|x + 2| + \log|x - 3| + C
\end{align*}
%
as required.
\end{proof}

\begin{example}
Use partial fraction expansion to compute
\[
\int \frac{x^2}{(x - 3) (x + 2)^2} \, dx.
\]
\end{example}

\begin{proof}[Solution]
By the partial fraction theorem, there are constants $A, B, C$ such that
\[
\frac{x^2}{(x - 3) (x + 2)^2}
=
\frac{A}{x - 3} + \frac{B}{x + 2} + \frac{C}{(x + 2)^2}.
\]
Note that there is no possible way this could work without the
$(x + 2)^2$ term, since otherwise the common denominator would be
$(x - 3) (x + 2)$. We have
%
\begin{align*}
A
&=
\left[ f(x) (x - 3)\right]_{x=3}
=
\left. \frac{x^2}{(x + 2)^2} \right|_{x=3}
=
\frac{9}{25} \\
C
&=
\left[ f(x) (x + 2)^2 \right]_{x=-2}
=
-\frac{4}{5}.
\end{align*}
%
This method will not get us $B$! For example,
\[
f(x) (x + 2)
=
\frac{x^2}{(x - 3) (x + 2)}
=
A \cdot \frac{x + 2}{x - 3} + B + \frac{C}{x + 2}.
\]
While true this is useless. Instead, we use the fact that we know $A$
and $C$, and evaluate at another value of $x$, say $0$:
\[
f(0)
=
0
=
\frac{9/25}{-3} + \frac{B}{2} + \frac{-4/5}{2^2}
\]
so $B = \frac{16}{25}$. Thus
%
\begin{align*}
\int \frac{x^2}{(x - 3) (x + 2)^2} \, dx
&=
\int \frac{9/25}{x - 3} + \frac{16/25}{x + 2} +
\frac{-4/5}{(x + 2)^2} \, dx \\
&=
\frac{9}{25} \ln|x - 3| + \frac{16}{25} \ln|x + 2| + \frac{4/5}{x + 2} + C
\end{align*}
%
as required.
\end{proof}

\begin{example}
Compute
\[
\int \frac{1}{x^3 + 1} \, dx.
\]
\end{example}

\begin{proof}[Solution]
Notice that $x + 1$ is a factor of $x^3 + 1$, since $-1$ is a root:
\[
x^3 + 1
=
(x + 1) (x^2 - x + 1).
\]
There exist constants $A, B, C$ such that
\[
\frac{1}{x^3 + 1}
=
\frac{A}{x + 1} + \frac{Bx + C}{x^2 - x + 1}.
\]
Then
\[
A
=
f(x)(x + 1)|_{x=-1}
=
\frac{1}{3}.
\]
You could find $B$ and $C$ by factoring the quadratic over the complex
numbers and getting complex number answers. Instead, we evaluate $x$
at a couple of values. For example, at $x = 0$ we get
\[
f(0)
=
1
=
\frac{1}{3} + \frac{C}{1}
\]
so $C = \frac{2}{3}$. Next, use $x = 1$ to get $B$:
%
\begin{align*}
f(1)
&=
\frac{1}{1^3 + 1} \\
&=
\frac{1/3}{1 + 1} + \frac{B + 2/3}{1^2 - 1 + 1} \\
\frac{1}{2}
&=
\frac{1}{6} + B + \frac{2}{3}
\end{align*}
%
so that
\[
B
=
\frac{3}{6} - \frac{1}{6} - \frac{4}{6}
=
-\frac{1}{3}.
\]
Finally,
%
\begin{align*}
\int \frac{1}{x^3 + 1} \, dx
&=
\int \frac{1/3}{x + 1} - \frac{1/3 x}{x^2 - x - 1} +
\frac{2/3}{x^2 - x - 1} \, dx \\
&=
\frac{1}{3} \ln|x + 1| -
\frac{1}{3} \int \frac{x - 2}{x^2 - x + 1} \, dx.
\end{align*}
%
It remains to compute
\[
\int \frac{x - 2}{x^2 - x + 1} \, dx.
\]
First, complete the square to get
\[
x^2 - x + 1
=
\left( x - \frac{1}{2} \right)^2 + \frac{3}{4}.
\]
Let $u = (x - 1/2)$ so $du = dx$ and $x = u + 1/2$. Then
%
\begin{align*}
\int \frac{u - 3/2}{u^2 + 3/4} \, du
&=
\int \frac{u \, du}{u^2 + 3/4} -
\frac{3}{2} \int\frac{1}{u^2 + \left(\frac{\sqrt{3}}{2}\right)^2} \, du \\
&=
\frac{1}{2} \ln\left|u^2 + \frac{3}{4}\right| -
\frac{3}{2} \cdot \frac{2}{\sqrt{3}}
\tan^{-1} \left( \frac{2u}{\sqrt{3}} \right) + C \\
&=
\frac{1}{2} \ln\left|x^2 - x + 1\right| -
\sqrt{3} \tan^{-1} \left(\frac{2x - 1}{\sqrt{3}}\right) + C.
\end{align*}
%
Finally, we put it all together to obtain
%
\begin{align*}
\int \frac{1}{x^3 + 1} \, dx
&=
\frac{1}{3} \ln|x + 1| - \frac{1}{3} \int \frac{x - 2}{x^2 - x + 1} \, dx \\
&=
\frac{1}{3} \ln|x + 1| - \frac{1}{6} \ln\left|x^2 - x + 1\right| +
\frac{\sqrt{3}}{3} \tan^{-1} \left(\frac{2x - 1}{\sqrt{3}}\right) + C
\end{align*}
%
as required.
\end{proof}

%\forclass{Discuss second quiz problem.

Computing $\int \cos^2(x) e^{-3x} \, dx$ using complex exponentials,
we get
\[
-\frac{1}{6} e^{-3x} + \frac{1}{13} e^{-3x} \sin(2x) -
\frac{3}{26} e^{-3x} \cos(2x) + C.
\]
Here is how to get it:
%
\begin{align*}
\int \cos^2(x) e^{-3x} \, dx
&=
\int \frac{e^{2ix} + 2 + e^{-2ix}}{4} e^{-3x} \, dx \\
&=
\frac{1}{4} \left[
  \frac{e^{(2i - 3)x}}{2i - 3} - \frac{2}{3} e^{-3x} +
  \frac{e^{(-2i - 3)x}}{-2i - 3} \right] + C \\
&=
-\frac{1}{6} e^{-3x} + \frac{e^{-3x}}{4} \left[
  \frac{e^{2ix}}{2i - 3} - \frac{e^{-2ix}}{2i + 3} \right] + C.
\end{align*}
%
Simplifying the inside part requires some imagination:
%
\begin{align*}
\frac{e^{2ix}}{2i - 3} - \frac{e^{-2ix}}{2i + 3}
&=
\frac{1}{13} (-2i e^{2ix} - 3e^{2ix} + 2i e^{-2ix} - 3 e^{-2ix}) \\
&=
\frac{1}{13} (4\sin(2x) - 6\cos(2x)).
\end{align*}


%%-----------------------------------------------------------------------%%
%%--- Improper integrals ------------------------------------------------%%

\section{Improper integrals}
\index{improper integrals}

\begin{example}
Make sense of $\ds \int_0^{\infty} e^{-x} \, dx$.
\end{example}

\begin{proof}[Solution]
%gnuplot.plot('plot [0:10] exp(-x)', 'example_ex_improper')
The integral
\[
\int_0^t e^{-x} \, dx
\]
make sense for each real number $t$. So consider
\[
\lim_{t \to \infty} \int_0^t e^{-x} \, dx
=
\lim_{t \to \infty} \Bigl[ -e^{-x} \Bigr]_0^t
=
1.
\]
Geometrically, the area under the whole curve is the limit of the
areas for finite values of $t$.
%\fig{Graph of $e^{-x}$}{example_ex_improper}
\end{proof}

\begin{example}
Compute the integral
\[
\int_0^1 \frac{1}{\sqrt{1 - x^2}} \, dx.
\]
%(see Figure~\ref{example_ex_improper_blowup}).
%\fig{Graph of $\frac{1}{\sqrt{1-x^2}}$\label{example_ex_improper_blowup}}{example_ex_improper_blowup}
%gnuplot.plot('plot [0:1] 1/sqrt(1-x^2)', 'example_ex_improper_blowup')
\end{example}

\begin{proof}[Solution]
The denominator of the integrand tends to $0$ as $x$ approaches the
upper endpoint. Define
%
\begin{align*}
\int_0^1 \frac{1}{\sqrt{1 - x^2}} \, dx
&=
\lim_{t \to 1^-} \int_0^t\frac{1}{\sqrt{1 - x^2}} \, dx \\
&=
\lim_{t \to 1^-} \Bigl( \sin^{-1}(t) - \sin^{-1}(0) \Bigr) \\
&=
\sin^{-1}(1) \\
&=
\frac{\pi}{2}
\end{align*}
%
Here $t \to 1^-$ means the limit as $t$ tends to $1$
\emph{from the left}.
\end{proof}

\begin{example}
\label{ex:multipleimproper}
There can be multiple points at which the integral is improper. For
example, compute
\[
\int_{-\infty}^{\infty} \frac{1}{1 + x^2} \, dx.
\]
\end{example}

\begin{proof}[Solution]
A crucial point is that we take the limit for the left and right
endpoints independently. We use the point $0$ (for convenience only)
to break the integral in half:
%
\begin{align*}
\int_{-\infty}^{\infty} \frac{1}{1 + x^2} \, dx
&=
\int_{-\infty}^0 \frac{1}{1 + x^2} \, dx  +
\int_0^{\infty} \frac{1}{1 + x^2} \, dx \\
&=
\lim_{s \to -\infty} \int_s^0 \frac{1}{1 + x^2} \, dx  +
\lim_{t \to \infty} \int_0^t \frac{1}{1 + x^2} \, dx \\
&=
\lim_{s \to -\infty} \big( \tan^{-1}(0) - \tan^{-1}(s) \big) +
\lim_{t \to \infty} \big( \tan^{-1}(t) - \tan^{-1}(0) \big) \\
&=
\lim_{s \to -\infty} \big( -\tan^{-1}(s) \big) +
\lim_{t \to \infty} \big( \tan^{-1}(t) \big) \\
&=
-\frac{-\pi}{2} + \frac{\pi}{2}.
\end{align*}
%
This simplifies to $\pi$.
%The graph of $\tan^{-1}(x)$ is in Figure~\ref{fig:example_atan}.
%\fig{Graph of $\tan^{-1}(x)$\label{fig:example_atan}}{example_atan}
%gnuplot.plot('plot [-20:20] atan(x)', 'example_atan.eps')
\end{proof}

%\begin{example}
%\label{ex:noant}
%Brian Conrad's paper on impossibility theorems for elementary
%integration begins: ``The Central Limit Theorem in
%probability theory assigns a special significance to
%the cumulative area function
% $$\Phi(x) = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^x e^{-u^2}{u} du$$
%under the Gaussian bell curve
%$$
%  y=\frac{1}{\sqrt{2\pi}} \cdot e^{-u^2/2}.
%$$
%It is known that $\Phi(\infty) = 1$.''
%
%What does this last statement {\em mean}?  It means that
%$$
%   \lim_{t\to\infty} \frac{1}{\sqrt{2\pi}} \int_{-t}^0 e^{-u^2}{u} du
%+ \lim_{x\to\infty} \frac{1}{\sqrt{2\pi}} \int_{0}^x e^{-u^2}{u} du
%= 1.
%$$
%\end{example}

\begin{example}
Compute the integral
\[
\int_{-\infty}^{\infty} x \, dx.
\]
\end{example}

\begin{proof}[Solution]
Notice that
\[
\int_{-\infty}^{\infty} x \, dx
=
\lim_{s \to -\infty} \int_s^0 x \, dx +
\lim_{t \to \infty} \int_0^t x \, dx.
\]
This diverges since each factor diverges independently. But notice
that
\[
\lim_{t \to \infty} \int_{-t}^t x \, dx
=
0.
\]
This is \emph{not} what $\int_{-\infty}^{\infty} x \, dx$ means (in
this book). This illustrates the importance of treating each bad point
separately (since Example~\ref{ex:multipleimproper} does not).
\end{proof}

\begin{example}
Compute the integral
\[
\int_{-1}^1 \frac{1}{\sqrt[3]{x}} \, dx.
\]
\end{example}

\begin{proof}[Solution]
We have
%
\begin{align*}
\int_{-1}^1 \frac{1}{\sqrt[3]{x}} \, dx
&=
\lim_{s \to 0^-} \int_{-1}^s x^{-\frac{1}{3}} \, dx +
\lim_{t \to 0^+} \int_t^1 x^{-\frac{1}{3}} \, dx \\
&=
\lim_{s \to 0^-} \left(
\frac{3}{2} s^{\frac{2}{3}} - \frac{3}{2} \right) +
\lim_{t \to 0^+} \left( \frac{3}{2} - \frac{3}{2} t^{\frac{2}{3}} \right) \\
&=
0.
\end{align*}
%
This illustrates how to be careful and break the function up into two
pieces when there is a discontinuity.
\end{proof}

%\forclass{
%{\bf\Large NOTES for 2006-02-22}\\
%Midterm 2: Wednesday, March 1, 2006, at 7pm in Pepper Canyon 109\\
%Today: 7.8: Comparison of Improper integrals\\
%11.1: Sequences\\
%Next 11.2 Series\\
%}

\begin{example}
Compute the integral
\[
\int_{-1}^3 \frac{1}{x - 2} \, dx.
\]
\end{example}

\begin{proof}[Solution]
Before this section, you might have done this:
\[
\int_{-1}^3 \frac{1}{x - 2} \, dx
=
\Bigl[ \ln|x - 2| \Bigr]_{-1}^3
=
\ln(3) - \ln(1) \qquad{\text{(totally wrong!)}}
\]
This is not valid because the function we are integrating has a pole
at $x = 2$. % (see Figure~\ref{fig:example_invx2}).
The integral is improper and is only defined if both the following
limits exists:
\[
\lim_{t \to 2^-} \int_{-1}^t \frac{1}{x - 2} \, dx
\qquad\text{and}\qquad
\lim_{t \to 2^+} \int_{t}^3 \frac{1}{x - 2} \, dx.
\]
However, the limits diverge, e.g.
\[
\lim_{t \to 2^+} \int_t^3 \frac{1}{x - 2} \, dx
=
\lim_{t \to 2^+} (\ln|1| - \ln|t-2|)
=
-\lim_{t \to 2^+} \ln|t - 2|
=
-\infty.
\]
Thus $\int_{-1}^3 \frac{1}{x - 2} \, dx$ is divergent.
%\fig{Graph of $\frac{1}{x-2}$\label{fig:example_invx2}}{example_invx2}
%gnuplot.plot('plot [-1:3] 1/(x-2)', 'example_invx2.eps')
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Convergence, divergence, and comparison ---------------------------%%

\subsection{Convergence, divergence, and comparison}
\index{convergence}
\index{divergence}

In this section, we discuss using comparison to determine if an
improper integral converges or diverges. Recall that if $f$ and $g$
are continuous functions on an interval $[a, b]$ and $g(x) \leq f(x)$,
then
\[
\int_a^b g(x) \, dx \leq \int_a^b f(x) \, dx.
\]
This observation can be \emph{incredibly useful} in determining
whether or not an improper integral converges. Not only does this
technique help in determining whether integrals converge, but it also
gives you some information about their values, which is often much
easier to obtain than computing the exact integral.

\begin{theorem}
\label{thm:comparison}
\textbf{Comparison test (special case).}
\index{comparison test}
Let $f$ and $g$ be continuous functions with $0 \leq g(x) \leq f(x)$
for $x \geq a$.
%
\begin{enumerate}
\item If $\int_a^{\infty} f(x) \, dx$ converges, then
$\int_a^{\infty} g(x) \, dx$ converges.

\item If $\int_a^{\infty} g(x) \, dx$ diverges, then
$\int_a^{\infty} f(x) \, dx$ diverges.
\end{enumerate}
\end{theorem}

\begin{proof}
Since $g(x) \geq 0$ for all $x$, the function
\[
G(t)
=
\int_a^t g(x) \, dx
\]
is a non-decreasing function. If $\int_a^{\infty} f(x) \, dx$
converges to some value $B$, then for any $t \geq a$ we have
\[
G(t)
=
\int_a^t g(x) \, dx \leq \int_a^t f(x) \, dx \leq B.
\]
Thus in this case $G(t)$ is a non-decreasing function bounded above,
hence the limit $\lim_{t \to \infty} G(t)$ exists. This proves the
first statement.

Likewise, the function
\[
F(t)
=
\int_a^t f(x) \, dx
\]
is also a non-decreasing function. If $\int_a^{\infty} g(x) \, dx$
diverges then the function $G(t)$ defined above is still
non-decreasing and $\lim_{t \to \infty} G(t)$ does not exist, so
$G(t)$ is not bounded. Since $g(x) \leq f(x)$, we have
$G(t) \leq F(t)$ for all $t \geq a$, hence $F(t)$ is also unbounded,
which proves the second statement.
\end{proof}

The theorem is very intuitive if you think about areas under a graph.
``If the bigger integral converges then so does the smaller one, and
if the smaller one diverges so does the bigger ones.''

\begin{example}
Does the integral
\[
\int_0^{\infty} \frac{\cos^2(x)}{1 + x^2} \, dx
\]
converge?
\end{example}

%\fig{Graph of $\frac{\cos(x)^2}{1+x^2}$
%and $\frac{1}{1+x^2}$\label{fig:example_compare1}}{example_compare1}
%gnuplot.plot('plot [0:10] cos(x)^2/(1+x^2), 1/(1+x^2)', 'example_compare1.eps')

\begin{proof}[Solution]
Since $0 \leq \cos^2(x) \leq 1$, we really do have
\[
0 \leq \frac{\cos^2(x)}{1 + x^2} \leq \frac{1}{1 + x^2}.
\]
%as illustrated in Figure~\ref{fig:example_compare1}.
Thus
\[
\int_0^{\infty} \frac{1}{1 + x^2} \, dx
=
\lim_{t \to \infty} \tan^{-1}(t)
=
\frac{\pi}{2}
\]
so $\int_0^{\infty} \frac{\cos^2(x)}{1+x^2}dx$ converges.

But why did we use $\frac{1}{1 + x^2}$?  It is a \emph{guess} that
turned out to work. You could have used something else, e.g.
$\frac{c}{x^2}$ for some constant $c$. This is an illustration of how
in mathematics sometimes you have to use your imagination or guess and
see what happens. Do not get anxious---instead, relax, take a deep
breath and explore.

For example, alternatively we could have done the following:
\[
\int_1^{\infty} \frac{\cos^2(x)}{1 + x^2} \, dx
\leq
\int_1^{\infty} \frac{1}{x^2} dx
=
1.
\]
This works just as well, since
\[
\int_0^1 \frac{\cos^2(x)}{1 + x^2} \, dx
\]
converges (as $\frac{\cos^2(x)}{1 + x^2}$ is continuous).
\end{proof}

\begin{example}
Consider the integral
\[
\int_0^{\infty} \frac{1}{x + e^{-2x}} \, dx.
\]
Does it converge or diverge?
\end{example}

\begin{proof}[Solution]
For large values of $x$, the term $e^{-2x}$ very quickly goes to $0$,
so we expect this to diverge, since $\int_1^{\infty} \frac{1}{x} \, dx$
diverges.
%Note that we can change the lower limit to $1$ since
%$\int_{0}^{1} \frac{1}{x+e^{-2x}} dx$ converges, being the
%integral of a continuous function on a closed interval.
%So instead we will consider
%$\int_{1}^{\infty} \frac{1}{x+e^{-2x}} dx$ for the rest of this problem.
For $x \geq 0$, we have $e^{-2x} \leq 1$, so for all $x$ we have
\[
\frac{1}{x + e^{-2x}} \geq \frac{1}{x + 1}
\qquad\text{(verify by cross multiplying)}.
\]
But
\[
\int_1^{\infty} \frac{1}{x + 1} \, dx
=
\lim_{t \to \infty} \Bigl[ \ln(x + 1) \Bigr]_1^t
=
\infty.
\]
Thus $\int_0^{\infty} \frac{1}{x + e^{-2x}} \, dx$ must also diverge.
\end{proof}

Note that there is a natural analogue of Theorem~\ref{thm:comparison}
for integrals of functions that ``blow up'' at a point, but we will
not state it formally.

\begin{example}
Compute the integral
\[
\int_0^1 \frac{e^{-x}}{\sqrt{x}} \, dx
=
\lim_{t \to 0^+} \int_t^1 \frac{e^{-x}}{\sqrt{x}} \, dx.
\]
\end{example}

\begin{proof}[Solution]
We have
\[
\frac{e^{-x}}{\sqrt{x}} \leq \frac{1}{\sqrt{x}}.
\]
(Coming up with this comparison might take some work, imagination,
and trial and error.) We have
\[
\int_0^1 \frac{e^{-x}}{\sqrt{x}} \, dx
\leq
\int_0^1 \frac{1}{\sqrt{x}} \, dx
=
\lim_{t \to 0^+} 2\sqrt{1} - 2\sqrt{t}
=
2
\]
thus $\int_0^1 \frac{e^{-x}}{\sqrt{x}} \, dx$ converges, even though
we have not figured out its value. We just know that it is $\leq 2$.
(In fact, it is $1.493648265\ldots$.)

What if we found a function that is bigger than
$\frac{e^{-x}}{\sqrt{x}}$ and its integral diverges?
\end{proof}

\begin{example}
Does the integral
\[
\int_0^1 \frac{e^{-x}}{x} \, dx
\]
converge or diverge?
\end{example}

\begin{proof}[Solution]
This is an improper integral since $f(x) = \frac{e^{-x}}{x}$ has a
pole at $x = 0$. Does it converge? No. On the interval $[0, 1]$ we
have $e^{-x} \geq e^{-1}$. Thus
%
\begin{align*}
\lim_{t \to 0^+} \int_t^1 \frac{e^{-x}}{x} \, dx
&\geq
\lim_{t \to 0^+} \int_t^1 \frac{e^{-1}}{x} \, dx \\
&=
e^{-1} \cdot \lim_{t \to 0^+} \int_t^1 \frac{1}{x} \, dx \\
&=
e^{-1} \cdot \lim_{t \to 0^+} \ln(1) - \ln(t) \\
&=
+\infty.
\end{align*}
%
Thus $\int_0^1 \frac{e^{-x}}{x} \, dx$ diverges.
\end{proof}
